package com.hwz.gulimaill.thridParty.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

/**
 * @Author: hwz
 * @CreateTime: 2025-10-18
 */

@Service
@Slf4j
public class SmsService {
    @Resource
    JavaMailSender javaMailSender;

    public String sendCode(String phone, String code) throws Exception {

        MimeMessage message = javaMailSender.createMimeMessage(); // 使用 jmsi 而不是 javaMailSender
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
        //邮件发送人（这里也必须填写，和上边设置的授权码的qq邮箱一致）
        helper.setFrom("1281561921@qq.com");
        //邮件接收人
        helper.setTo(phone);
        helper.setSubject("灰太狼的谷粒商城的验证码");
        //邮件主题
        //邮件内容
        helper.setText( "【gulimall】验证码：" +code,true);
        javaMailSender.send(message);
        return "发送成功";

    }
}
